<?php

namespace app\web\controller;

use app\web\service\ArticleService;

// 文章控制器
class ArticleController extends CommonController
{
    public function initialize()
    {
        $this->noCheckTokenAction = ["getAllArticleType", "getChooseArticle", "getArticleContent"];
        parent::initialize();
    }

    // 获取可用的文章类型
    public function getAllArticleType(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ArticleService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getHomeData(); // 处理业务
        return $this->return_result($this->returnData);
    }

    // 筛选出文章列表
    public function getChooseArticle(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ArticleService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getArticleByTypeId(); // 处理业务
        return $this->return_result($this->returnData);
    }

    // 获取文章内容
    public function getArticleContent(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ArticleService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getArticleContentById(); // 处理业务
        return $this->return_result($this->returnData);
    }
}
